package com.edward.puff.asyn.impl;

import com.edward.puff.asyn.TransLogRetryTask;
import com.edward.puff.config.PuffConfiguration;
import com.edward.puff.execute.PuffExecutor;
import com.edward.puff.repository.PuffTransLog;
import com.edward.puff.repository.TransLogRepository;
import lombok.Setter;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Edward
 * @Date: 2019/11/28 下午7:34
 */
public class TransLogDefaultRetryTask implements TransLogRetryTask {

    @Setter
    private Class<? extends TransLogRepository> globalRepoClass;

    @Resource
    private PuffExecutor puffExecutor;

    @Resource
    private PuffConfiguration puffConfig;


    @Scheduled(cron = "0/10 * * * * ? ")
    @Override
    public void retry() {
        System.out.println("task===>>>>>>>12334");
        TransLogRepository repository = puffConfig.getBean(globalRepoClass);
        List<PuffTransLog> transLogs = repository.queryRetryTranLogs(100);
        transLogs.forEach(txLog -> {
            puffExecutor.execute(txLog);
        });
    }
}
